IF exists(SELECT * FROM dbo.sysobjects WHERE name='SGmaakNaam1Aan' AND xtype='P') 
BEGIN
	DROP PROCEDURE SGmaakNaam1Aan
END
GO

create procedure SGmaakNaam1Aan
as
set nocount on

declare @achternaam varchar(50)
declare @naam1 varchar(50)

declare deCursor cursor local for
select l.achternaam
from SGpersoneel as l 
order by l.achternaam

open deCursor
fetch next from deCursor 
      	into @achternaam

while (@@fetch_status=0)
  begin

    select @naam1 = lower(@achternaam)
    while charindex(' ',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex(' ',@naam1),1,'')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'e')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'i')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'c')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'e')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'o')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'e')
    while charindex('',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('',@naam1),1,'a')
    while charindex('''',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('''',@naam1),1,'')
    while charindex('-',@naam1) > 0 
	select @naam1 = stuff(@naam1,charindex('-',@naam1),1,'')

    update SGpersoneel
    set naam1=@naam1
    fetch next from deCursor into @achternaam
  end

close deCursor 	
deallocate deCursor